package com.timoon.sample.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.timoon.sample.dao.ProductCommentDAO;
import com.timoon.sample.dao.ProductDAO;
import com.timoon.sample.dao.ProductInstructionPicDAO;
import com.timoon.sample.dao.ProductPropertyDAO;
import com.timoon.sample.dao.model.Product;
import com.timoon.sample.dao.model.ProductComment;
import com.timoon.sample.dao.model.ProductCommentExample;
import com.timoon.sample.dao.model.ProductExample;
import com.timoon.sample.dao.model.ProductInstructionPic;
import com.timoon.sample.dao.model.ProductInstructionPicExample;
import com.timoon.sample.dao.model.ProductProperty;
import com.timoon.sample.dao.model.ProductPropertyExample;
import com.timoon.webcomponent.utility.product.linepic.HorizontalList4PicProductPanelService;
import com.timoon.webcomponent.utility.product.single.SingleProductService;
import com.timoon.webcomponent.utility.product.single.component.ProductCommentListService;
import com.timoon.webcomponent.utility.product.single.component.ProductDetailTabService;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */

@Service("com.timoon.webcomponent.utility.product.service.ProductService")
public class ProductServiceImpl implements SingleProductService,HorizontalList4PicProductPanelService
					,ProductDetailTabService,ProductCommentListService{

	@Resource
	private ProductDAO productDAOImpl;
	
	@Resource
	private ProductPropertyDAO productPropertyDAOImpl;
	
	@Resource
	private ProductCommentDAO productCommentDAOImpl;
	
	@Resource
	private ProductInstructionPicDAO productInstructionPicDAOImpl;
	
	public ProductInstructionPicDAO getProductInstructionPicDAOImpl() {
		return productInstructionPicDAOImpl;
	}

	public void setProductInstructionPicDAOImpl(
			ProductInstructionPicDAO productInstructionPicDAOImpl) {
		this.productInstructionPicDAOImpl = productInstructionPicDAOImpl;
	}

	@Override
	public Product loadProductById(Integer id) {
		// TODO Auto-generated method stub
		return this.productDAOImpl.selectByPrimaryKey(id);
	}

	public ProductPropertyDAO getProductPropertyDAOImpl() {
		return productPropertyDAOImpl;
	}

	public void setProductPropertyDAOImpl(ProductPropertyDAO productPropertyDAOImpl) {
		this.productPropertyDAOImpl = productPropertyDAOImpl;
	}

	public ProductDAO getProductDAOImpl() {
		return productDAOImpl;
	}

	public ProductCommentDAO getProductCommentDAOImpl() {
		return productCommentDAOImpl;
	}

	public void setProductCommentDAOImpl(ProductCommentDAO productCommentDAOImpl) {
		this.productCommentDAOImpl = productCommentDAOImpl;
	}

	public void setProductDAOImpl(ProductDAO productDAOImpl) {
		this.productDAOImpl = productDAOImpl;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Product> getProductByType(final Integer type) {
		// TODO Auto-generated method stub
		return this.productDAOImpl.selectByExample(new ProductExample(){{
			this.createCriteria().andStatusNotEqualTo(0).andTypeEqualTo(type);
		}});
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ProductProperty> getProductPropertyListByProductId(final Integer id) {
		// TODO Auto-generated method stub
		return this.productPropertyDAOImpl.selectByExample(new ProductPropertyExample(){{
			this.createCriteria().andStatusNotEqualTo(0).andProductIdEqualTo(id);
		}});
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ProductComment> getAllCommentByProductId(final Integer id) {
		// TODO Auto-generated method stub
		return this.productCommentDAOImpl.selectByExample(new ProductCommentExample(){{
			this.createCriteria().andPublicedNotEqualTo(0).andProductIdEqualTo(id);
		}});
	}

	@Override
	public Product getProductById(Integer id) {
		// TODO Auto-generated method stub
		return this.productDAOImpl.selectByPrimaryKey(id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ProductInstructionPic> getProductInstructionPicsByProductId(
			final Integer id) {
		// TODO Auto-generated method stub
		return this.productInstructionPicDAOImpl.selectByExample(new ProductInstructionPicExample(){{
			this.createCriteria().andProductIdEqualTo(id);
		}});
	}


	
}
